import argparse
import os
import socket
from app import app, parse_storage_size, get_local_ip

def main():
    parser = argparse.ArgumentParser(description="Run the Flask application.")
    parser.add_argument('-d', '--directory', default='./data', help='Directory to serve files from (default: ./data)')
    parser.add_argument('-s', '--storage', default='1G', help='Maximum storage size (default: 1G, 0 for unlimited)')

    args = parser.parse_args()

    app.config['UPLOAD_FOLDER'] = args.directory
    max_storage_size = parse_storage_size(args.storage)
    app.config['MAX_CONTENT_LENGTH'] = max_storage_size if max_storage_size > 0 else None

    ip = get_local_ip()
    print(f"启动HTTP服务: http://{ip}:8011/static 服务所在的文件目录是 {args.directory}")
    app.run(host='0.0.0.0', port=8011)
    
if __name__ == '__main__':
    main()
